#ifndef RULESET_H
#define RULESET_H
#pragma once
#include <string>
#include <map>
#include <windows.h>
#define URL_MAX_LEN 50
#define CMD_MAX_LEN 50
#define  CMPSTRING_BIGGER  "B"
#define  CMPSTRING_LESS		"L"
#define EVENTRESULT   "$eventResult"    //use for rule engine
using namespace std;

typedef enum
{
	WEBCALLWEB,//IF (callserviceA) goto webserviceB
	LOGCALLWEB,//if(logical )  goto webserviceA
}RULE_TYPE;

typedef enum{
	CALLWS,   //call web services
	ACTYPE_UNKNOW 
}actionType;

#define MACHSUCC   0
#define MACHFAIL   1
#define NOTIMETOMACH 2

#define FNAME_CALWS  "callwebservice"

typedef enum
{	
	EQAUL,
	RET_BIGERTHAN_DST,
	RET_LITERTHAN_DST,
	CMPTYPE_UNKNOW
}RuleCmpType;

typedef struct pa
{
	char url[URL_MAX_LEN];
	char cmd[CMD_MAX_LEN];
}PARA_FOR_WEBSERVICE;


class CRule
{
public:
	CRule()
	{
		lastActionTime =0;
	}
//	long timeval;
	UINT pri;
	int do_event(void);
	void do_action(void);
	void create_eca_rule(UINT priority,string time,string event,
	string condition_dest,string action,string owner,string Comparetype );
	void exe_eca_rule();
	int getMachResult();
	RuleCmpType getCompareType();
	time_t getLastActiontime()
	{
		return lastActionTime;
	}

//	RULE_TYPE rule_type;
	string str_time;
	string str_event;
	string str_condition;
	string str_condition_dest;
	string str_action;
	string str_owner;
	string str_Comparetype;   //can be "=" ">" and "<"
	bool active;
private:
	time_t lastActionTime;
		
};
class CRuleSet
{
public:
	CRuleSet(void);
	~CRuleSet(void);
	
	int add_rule(string name,CRule rule);
	string del_rule(string name);
	map<string,CRule>::iterator GethighestRule();
	bool Is_Ruleset_all_sleep();
	void refresh_rule_staus();
	void del_neighbour_ruleset(string name);
	void StoreRule2DB(string rule_name,CRule & r1);
	void GetRuleFrmDB(void);
	bool IsEmpty();
	bool issupport(string express);

protected:
	map<string,CRule>m_Ruleset;
};

#endif